package com.google.project.server;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.project.client.Service.ProjectReportDetailService;
import com.google.project.server.entity.ProjectReport;
import com.google.project.shared.ProjectReportDetailDTO;

@SuppressWarnings("serial")
public class ProjectReportDetailServiceImpl extends RemoteServiceServlet
		implements ProjectReportDetailService {
	@Override
	public List<ProjectReportDetailDTO> getProjectReportDetail(
			String projectReportId) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		ProjectReport projectReportInfo=null;
		List<ProjectReportDetailDTO> list = new ArrayList<ProjectReportDetailDTO>();
		try {
			projectReportInfo = pm
					.getObjectById(ProjectReport.class, projectReportId);
			if (projectReportInfo.getListOfReportDetail() != null) {
				for (int i = 0; i < projectReportInfo.getListOfReportDetail()
						.size(); i++) {
					list.add(projectReportInfo.getListOfReportDetail().get(i)
							.toDTO());
				}
			}
		}catch(Exception ex){
			ex.fillInStackTrace();
		} finally {
			pm.close();
		}

		return list;
	}


}
